/*
 *  motiondetect.h
 *  Woochy
 *
 *  Created by MiGi on 11/15/09.
 *  Copyright 2009 OSU. All rights reserved.
 *
 */
#ifndef MOTION_DETECT
#define MOTION_DETECT

#include "cv.h"
#include "highgui.h"

class Mei{
    IplImage *img;
public:
    Mei(CvSize &size) {
        img = cvCreateImage( size, 8, 1);
    }
    void update_image(IplImage *img1) {
        
    }
};
class Mhi{
    IplImage *mhi, *preImg, *tmp;
    double timestamp;
    bool firsttime;
public:
    Mhi(CvSize &size) {
        firsttime=true;
        mhi = cvCreateImage(size, IPL_DEPTH_32F, 1);
        preImg = cvCreateImage(size, 8,1);
        tmp = cvCreateImage(size, 8,1);
        timestamp = 0;
    }
    virtual ~Mhi() {
        cvReleaseImage(&mhi);
        cvReleaseImage(&preImg);
        cvReleaseImage(&tmp);
    }
    
    void update_image(IplImage *img) {
        if (!firsttime) {
            cvSub(img, preImg, tmp, NULL);
            cvUpdateMotionHistory(tmp, mhi, timestamp, 5);

        }else {
            firsttime=false;
        }

        cvCopy(img, preImg);
        timestamp+=1.0;
    }
    void show() {
        cvNamedWindow("MHI", 0);
        cvShowImage("MHI", mhi);
    }
};
    


#endif